Skip to content

fix(host-service): pin diff prefixes so user git config cannot break the Changes pane - #7652

Closed
sahiljagtap08 wants to merge 1 commit into
ParadevAI:mainfrom
sahiljagtap08:fix/diff-patch-prefix-pinning
Closed

sahiljagtap08 wants to merge 1 commit into
ParadevAI:mainfrom
sahiljagtap08:fix/diff-patch-prefix-pinning

Conversation

@sahiljagtap08

@sahiljagtap08 sahiljagtap08 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7596

What was broken

With diff.mnemonicPrefix = true (or diff.noprefix = true) in the user's gitconfig, every file under Staged and Unstaged shows "Unable to load diff". The sidebar counts are right, and Against base and Commits still work, which made this hard to diagnose.

The pane parses patch text and expects diff --git a/... b/... headers, but git builds those prefixes from user config. Mnemonic prefixes turn them into i/ and w/ (unstaged), c/ and i/ (staged), and 1/ and 2/ (untracked via --no-index). diff.noprefix strips them everywhere, which would break Against base and Commits too. Comparing two commits is the one case where mnemonic prefixes happen to match a/ and b/, which is exactly why those two sections kept working.

The fix

Pin the four prefix settings at the invocation instead of teaching the parser every user's config. All five git diff argv builders in diff-patch.ts now start with:

-c diff.mnemonicPrefix=false -c diff.noprefix=false -c diff.srcPrefix=a/ -c diff.dstPrefix=b/

I used -c rather than --default-prefix on purpose: --default-prefix needs git 2.45 and is a hard error below that, while unknown -c keys are silently ignored by every git version, so this has no version floor.

Tests

Three new tests in diff-patch.test.ts against real git repos: with diff.mnemonicPrefix, with diff.noprefix, and with custom srcPrefix/dstPrefix, the unstaged, staged, and untracked patches must all keep a/ and b/ headers. All three fail on main.

Out of scope

The issue also notes that the Retry button on the placeholder never refetches, and a possible quoting mismatch for non-ASCII filenames. Both are renderer concerns and worth their own issues; this PR fixes the reason the placeholder appears in the first place.


Summary by cubic

Fixes the Changes pane rendering "Unable to load diff" when user git config sets diff.mnemonicPrefix, diff.noprefix, or custom srcPrefix/dstPrefix, by pinning the prefix settings at every git diff invocation.

  • Pins diff.mnemonicPrefix, diff.noprefix, diff.srcPrefix, and diff.dstPrefix with -c flags in all five diff argument builders in diff-patch.ts.
  • Uses -c instead of --default-prefix so there's no git version floor; unknown -c keys are ignored by older git.
  • Adds three tests covering mnemonic prefixes, noprefix, and custom prefixes, all of which fail on main.

Out of scope

  • The Retry button never refetches and a possible non-ASCII filename quoting mismatch remain open as renderer concerns.

Written for commit 572003b. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Fixed diff rendering when Git path-prefix settings are customized.
    • Ensured staged, unstaged, and untracked file diffs consistently display with recognizable a/ and b/ headers instead of appearing as unavailable.

…the Changes pane

The Changes pane parses patch headers expecting a/ and b/ prefixes, but
git derives those from user config. With diff.mnemonicPrefix or
diff.noprefix set, the Staged, Unstaged, and untracked sections all
render as Unable to load diff. Pin the four prefix settings with -c at
every diff invocation. Unknown -c keys are ignored on old git versions,
unlike --default-prefix which needs git 2.45.

Fixes ParadevAI#7596
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: a32fb955-ea75-459c-8d69-9f3b79071402

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc9d0c and 572003b.

📒 Files selected for processing (2)
  • packages/host-service/src/trpc/router/git/utils/diff-patch.test.ts
  • packages/host-service/src/trpc/router/git/utils/diff-patch.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change pins Git diff path prefixes to a/ and b/ for tracked and untracked patches. Tests verify this behavior when Git uses mnemonic, no-prefix, or custom prefix settings.

Changes

Diff prefix pinning

Layer / File(s) Summary
Pin prefixes in diff invocations
packages/host-service/src/trpc/router/git/utils/diff-patch.ts
Adds Git configuration overrides to all tracked and untracked diff commands.
Validate configured prefix variants
packages/host-service/src/trpc/router/git/utils/diff-patch.test.ts
Adds tests for unstaged, staged, and untracked patches with alternate Git prefix configurations.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: saddlepaddle

Merge Risk: ⚪ Minimal · up to 57200

The prefix handling is consistently applied across supported diff types, with isolated coverage for the affected Git configurations. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses conventional commit format and clearly identifies the main change: pinning Git diff prefixes to prevent user configuration from breaking the Changes pane.
Description check ✅ Passed The description explains the problem, root cause, fix, compatibility decision, tests, linked issue, and out-of-scope items. It does not include the template checklist, but the required change and test…
Linked Issues check ✅ Passed The changes satisfy the coding requirements in [#7596]. diff-patch.ts prepends -c diff.mnemonicPrefix=false, -c diff.noprefix=false, -c diff.srcPrefix=a/, and -c diff.dstPrefix=b/ to the Aga…
Out of Scope Changes check ✅ Passed The pull request changes only the diff invocation code and its automated tests. The changes directly address the prefix-related cause of the Unable to load diff placeholder in [#7596]. No unrelated …
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sahiljagtap08

Copy link
Copy Markdown
Contributor Author

Closing: #7597 landed the same prefix pinning at the spawn seam, plus core.quotePath, and covers everything here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changes pane can't render Staged/Unstaged diffs when git emits non-default diff prefixes (diff.mnemonicPrefix, diff.noprefix)

1 participant